<template>
  <div id="reportSearchList">
    <Breadcrumb content="阳性报表" />
    <div class="bodyContent">
      <Splitpanes>
        <Pane size="17">
          <el-scrollbar style="height: 100%">
            <vxe-form ref="searchConForm" :data="form" title-width="80" class-name="padding-xs width-100-percentage">
              <vxe-form-item title="工作组" class-name="width-100-percentage">
                <template #default>
                  <SelectWorkGroupAllDefaultAll ref="selectWt" :url="'/api/rptGroup/findRptGroup'" :inputWidth="'100%'" @fatherMethod="searchWklt" :isShowAll="true" :isClear="true"></SelectWorkGroupAllDefaultAll>
                </template>
              </vxe-form-item>
              <vxe-form-item title="检验日期[起]" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input v-model="data.sampledaS" type="date" placeholder="检验日期[起]" transfer :value-format="'yyyy-MM-dd'" :label-format="'yyyy-MM-dd'" class-name="width-100-percentage" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="检验日期[止]" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input v-model="data.sampledaE" type="date" placeholder="检验日期[止]" transfer :value-format="'yyyy-MM-dd'" :label-format="'yyyy-MM-dd'" class-name="width-100-percentage" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="病人类型" class-name="width-100-percentage">
                <template #default="{ data }">
                  <VxeDictSelection :url="'/api/sys/basDictDetail/findDictDetailList'" @confirmClick="pulldownSelectConfirm" :displayTexts="['name']" :displayTextObj="data.patType" :tableColumn="[{ field: 'code', title: '编码', width: `60px` }, { field: 'name', title: '名称', minWidth: `80px` }]" :aimKeys="[{ aimKey: 'patType', rowKey: 'code' }]" :dataObj="{ code: 'PATTYPE' }" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="标本号" field="sampleNo" class-name="width-100-percentage" :item-render="{}">
                <template #default="{ data }">
                  <vxe-input ref="codeInput " class-name="width-100-percentage" v-model="data.sampleNo" placeholder="请输入1,2,5-8等格式" clearable @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="样本类型" class-name="width-100-percentage">
                <template #default="{ data }">
                  <VxePulldownSelection :url="'/api/lab/labSampleType/findSampleTypeList'" @confirmClick="dropPullDownConfirm" :tableColumn="[{ field: 'sampleTypeCode', title: '编号', width: '60px' }, { field: 'sampleTypeName', title: '名称' }]" :aimKeys="[{ aimKey: 'sampleType', rowKey: 'sampleTypeCode' }]" :displayTexts="['sampleTypeNa']" :displayTextObj="data.sampleTypeNa ? data.sampleTypeNa : ''" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="科室" class-name="width-100-percentage">
                <template #default="{ data }">
                  <VxePulldownSelection @blur="findRptYangXList" :url="'/api/sys/findDepartmentListbyCurrentUserOrg'" @confirmClick="dropPullDownConfirm" :tableColumn="[{ field: 'code', title: '编码', width: '60px' }, { field: 'name', title: '名称' }]" :aimKeys="[{ aimKey: 'reqDept', rowKey: 'code' }, { aimKey: 'reqDeptNa', rowKey: 'name' }]" :displayTexts="['name']" :displayTextObj="data.reqDept ? data.reqDept : ''" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="性别" class-name="width-100-percentage">
                <template #default="{ data }">
                  <VxeDictSelection class="enterNextInputFlag" :url="'/api/sys/basDictDetail/findDictDetailList'" @confirmClick="dropSelectConfirm" :displayTexts="['name']" :displayTextObj="data.sex" :tableColumn="[{ field: 'code', title: '编码', width: `60px` }, { field: 'name', title: '名称', minWidth: `80px` }]" :aimKeys="[{ aimKey: 'sex', rowKey: 'code' }]" :dataObj="{ code: 'sex' }" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="条码号" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" v-model="data.reqNo" placeholder="条码号" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="是否审核" field="status" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-select class-name="width-100-percentage" @clear="selectClearHandler" v-model="data.status" placeholder="可清除" clearable>
                    <vxe-option value="1" label="全部"></vxe-option>
                    <vxe-option value="2" label="未审核"></vxe-option>
                    <vxe-option value="3" label="已初审"></vxe-option>
                    <vxe-option value="4" label="已审核"></vxe-option>
                  </vxe-select>
                </template>
              </vxe-form-item>
              <vxe-form-item title="检验项目" class-name="width-100-percentage">
                <template #default="{ data }">
                  <!-- <VxePulldownMultiSelection ref="cleanFeeItemSelection" childIndex="fee" url="/lis/fee/item/findFeeItemList" @confirmClick="(data) => confirmList(data, 'item')" :tableColumn="[
                    { field: 'feeCode', title: '编号' },
                    { field: 'feeName', title: '名称' }
                  ]" :displayTexts="['itemNa']" :displayTextObj="data.itemNa" :dicValues="data.itemNos" includeVal="id" /> -->
                  <VxePulldownMultiSelection url="/lis/lab/item/findLabItemDictList" @confirmClick="(data) =>confirmListItem(data,'item')" :tableColumn="[
                              { field: 'itemNo', title: '编号' },
                              { field: 'itemNa', title: '名称' }
                            ]" :aimKeys="[{ targetField: 'item', sourceField: 'item' }]" :displayTexts="['itemNa']" :displayTextObj="data.itemNa" :dicValues="data.itemNos" includeVal="id" :isQuickTable="true" qUrl="/api/rptGroup/findRptGroup" :quickColumn="[{ field: 'rptGroupName', title: '报告单元' }]" :quickFilterObj="[{ searchKey: 'rptGroup', selectKey: 'rptGroup' }]" />
                </template>
              </vxe-form-item>
              <vxe-form-item title="申请号" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" v-model="data.barcode" placeholder="申请号" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="临床诊断" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" v-model="data.diagnose" placeholder="临床诊断" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="检验目的" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" v-model="data.reqPurpose" placeholder="检验目的" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="电话号码" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" v-model="data.telNo" placeholder="电话号码" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
            </vxe-form>
            <el-divider content-position="left">阳性判断条件</el-divider>
            <vxe-form ref="searchConForm1" :data="form" title-width="80" class-name="padding-xs width-100-percentage">
              <vxe-form-item title="数值结果<" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="float" :disabled="data.multiConditions===1" v-model="data.leVal" placeholder="数值结果<" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="或数值结果>" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="float" :disabled="data.multiConditions===1" v-model="data.gtVal" placeholder="或数值结果>" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="文字结果=" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" :disabled="data.multiConditions===1" v-model="data.txtValEq" placeholder="文字结果=" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
              <vxe-form-item title="文字结果<>" class-name="width-100-percentage">
                <template #default="{ data }">
                  <vxe-input type="text" placeholder="文字结果<>" v-model="data.txtValNotEq" clearable class-name="width-100-percentage" @keydown="handleSearch"></vxe-input>
                </template>
              </vxe-form-item>
            </vxe-form>
            <vxe-form ref="searchConForm1" :data="form" class-name="padding-xs width-100-percentage">
              <vxe-form-item title="或数值结果<>" class-name="width-100-percentage">
                <template #title>
                  <vxe-checkbox content="文字模糊查询" v-model="form.txtValLikeFilter" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
                </template>
              </vxe-form-item>
              <vxe-form-item title="筛选不为空姓名" class-name="width-100-percentage">
                <template #title>
                  <vxe-checkbox content="筛选不为空姓名" v-model="form.filterNullName" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
                </template>
              </vxe-form-item>
              <vxe-form-item title="按标本日期降序" class-name="width-100-percentage">
                <template #title>
                  <vxe-checkbox content="按标本日期降序" v-model="form.orderDescByScheduleDate" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
                </template>
              </vxe-form-item>
              <vxe-form-item title="多项目条件" class-name="width-100-percentage">
                <template #title>
                  <vxe-checkbox content="多项目条件" class="text-bold" v-model="form.multiConditions" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
                </template>
                <template #default>
                  <div class="flex justify-end margin-right-xs">
                    <vxe-button content="条件" @click="multiCondModal = true"></vxe-button>
                  </div>
                </template>
              </vxe-form-item>
              <vxe-form-item title="" class-name="width-100-percentage">
                <template #title>
                  <span class="text-blue">说明:文字结果可以输入多个用,隔开</span>
                </template>
              </vxe-form-item>
            </vxe-form>
          </el-scrollbar>
          <vxe-modal v-model="SearchTemplateModal">
            <template #title>
              <span>输入模板名称</span>
            </template>
            <template #default>
              <vxe-input v-model="SearchTemplateName" placeholder="可清除" clearable></vxe-input>
              <vxe-button mode="text" @click="saveSearchTemplate" content="保存"></vxe-button>
            </template>
            <template #footer></template>
          </vxe-modal>
        </Pane>
        <Pane size="83">
          <vxe-toolbar perfect>
            <template #buttons>
              <vxe-button type="text" class="button-blue margin-right-sm" @click="findRptYangXList" icon="el-icon-search">查询</vxe-button>
              <vxe-button type="text" class="button-blue margin-right-sm" icon="el-icon-printer" :loading="isPrinting" @click="printTable">打印</vxe-button>
              <vxe-button type="text" class="button-blue margin-right-sm" icon="el-icon-mobile" @click="exportCVS">导出</vxe-button>
              <vxe-button type="text" class="button-blue margin-right-sm" content="重置条件" @click="resetForm"></vxe-button>
              <!-- <vxe-button type="text" class="button-blue margin-right-sm" content="保存查询模板" @click="saveTemplate"></vxe-button>

              <vxe-select @change="selectChange" v-model="searchName" placeholder="请选择模板" size="small">
                <vxe-option v-for="(item, index) in SearchTemplateList" :key="index" :value="item" :label="item.name"></vxe-option>
              </vxe-select>
              <vxe-button type="text" class="button-blue margin-left-sm" content="删除此模板" @click="deleteTemplate"></vxe-button> -->
            </template>
          </vxe-toolbar>
          <div style="height: calc(100% - 30px)">
            <vxe-table :export-config="{}" border ref="wLTable" v-loading="loading" height="100%" show-overflow :data="tableList" :keyboard-config="{ isArrow: true }" :sort-config="{ trigger: 'cell' }" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" @current-change="handleRowClick" :scroll-y="{ enabled: true }">
              <vxe-column type="seq" title="#" width="60"></vxe-column>
              <vxe-column field="patNo" title="病历号" width="120" show-overflow></vxe-column>
              <vxe-column field="patNa" title="姓名" width="60" show-overflow></vxe-column>
              <vxe-column field="sexNa" title="性别" width="50" show-overflow></vxe-column>
              <vxe-column field="ageStr" title="年龄" width="45" show-overflow></vxe-column>
              <vxe-column field="reqDeptNa" title="科室" width="80" show-overflow></vxe-column>
              <vxe-column field="bedNo" title="床号" width="60" show-overflow></vxe-column>
              <vxe-column field="feeType" title="费别" width="60" show-overflow></vxe-column>
              <vxe-column field="reqDoctorNa" title="送检医生" width="60" show-overflow></vxe-column>
              <vxe-column field="testDoctorNa" title="检验者" width="60" show-overflow></vxe-column>
              <vxe-column field="sampleda" title="检验日期" width="75" show-overflow></vxe-column>
              <vxe-column field="sampleNo" title="标本号" width="60" show-overflow></vxe-column>
              <vxe-column field="itemNa" title="检验项目" min-width="160" show-overflow></vxe-column>
              <vxe-column field="result" title="检验结果" width="80" show-overflow></vxe-column>
              <vxe-column field="instrNa" title="仪器" width="120" show-overflow></vxe-column>
              <vxe-column field="rptGroupNa" title="工作组" width="120" show-overflow></vxe-column>
            </vxe-table>
          </div>
        </Pane>
      </Splitpanes>
    </div>
    <vxe-modal v-model="multiCondModal" width="65vw" height="55vh">
      <template #title>
        <span class="text-bold">多项条件</span>
      </template>
      <template #default>
        <vxe-toolbar>
          <template #buttons>
            <vxe-checkbox content="必须同时满足所有条件" v-model="form.enableAllConds" :checked-value="1" :unchecked-value="0" class-name="padding-right-xs"></vxe-checkbox>
          </template>
        </vxe-toolbar>
        <Splitpanes style="height: calc(100% - 40px)">
          <Pane :size="90">
            <div style="height: 100%; overflow-y: auto">
              <div v-for="(m, i) in forms" :key="i" class="padding-lr-xs border radius solid line-gray" :class="[i > 0 ? 'margin-top-xs' : '', m.isActive ? 'bg-orange light' : '']" @click="optionClick(m, i)">
                <vxe-form :data="m" style="background-color: rgba(0, 0, 0, 0)">
                  <vxe-form-gather span="24">
                    <vxe-form-item title="报告单元" field="rptGroup" :item-render="{}" span="8">
                      <template #title>
                        <span class="padding-lr-xs">报告单元</span>
                      </template>
                      <template #default>
                        <SelectWorkGroupAllDefaultAll :ref="`selectWt${i}`" :url="'/api/rptGroup/findRptGroup'" :inputWidth="'100%'" @fatherMethod="(v1,v2)=>searchWklt1(v1,v2,i)" :isShowAll="true" :isClear="true"></SelectWorkGroupAllDefaultAll>
                      </template>
                    </vxe-form-item>
                    <vxe-form-item title="数值结果<" field="leVal" :item-render="{}" span="8">
                      <template #title>
                        <span class="padding-lr-xs">{{ `数值结果<` }}</span>
                      </template>
                      <template #default="{ data }">
                        <vxe-input v-model="data.leVal" type="float" placeholder="数值结果<" clearable></vxe-input>
                      </template>
                    </vxe-form-item>
                    <vxe-form-item title="或数值结果>" field="gtVal" span="8">
                      <template #title>
                        <span class="padding-lr-xs">{{ `或数值结果>` }}</span>
                      </template>
                      <template #default="{ data }">
                        <vxe-input v-model="data.gtVal" type="float" placeholder="数值结果<" clearable></vxe-input>
                      </template>
                    </vxe-form-item>
                  </vxe-form-gather>
                  <vxe-form-gather span="24">
                    <vxe-form-item title="检验项目" field="itemNa" :item-render="{}" span="8">
                      <template #title>
                        <span class="padding-lr-xs">{{ `检验项目` }}</span>
                      </template>
                      <template #default="{ data }">
                        <VxeDictSelection :url="'/lis/lab/item/findLabItemDictList'" :childIndex="i" @confirmClick="confirmListItem1" :displayTexts="['itemNa']" :displayTextObj="data.itemNa" :tableColumn="[{ field: 'itemNo', title: '编码', width: `60px` }, { field: 'itemNa', title: '名称', minWidth: `80px` }]" :aimKeys="[{ aimKey: 'itemNo', rowKey: 'itemNo' },{ aimKey: 'itemNa', rowKey: 'itemNa' }]" :dataObj="{rptGroup:data.rptGroup===''||data.rptGroup===null||data.rptGroup===undefined?'!@#QWE':data.rptGroup}" />
                      </template>
                    </vxe-form-item>
                    <vxe-form-item title="文字结果=" field="txtval" :item-render="{}" span="16">
                      <template #title>
                        <span class="padding-lr-xs">{{ `文字结果=` }}</span>
                      </template>
                      <template #default="{ data }">
                        <vxe-input v-model="data.txtValEq" placeholder="文字结果=" clearable></vxe-input>
                      </template>
                    </vxe-form-item>
                  </vxe-form-gather>
                </vxe-form>
              </div>
            </div>
          </Pane>
          <Pane :size="10">
            <div class="padding-lr-xs">
              <!-- <div class="margin-bottom-xs"><vxe-button style="width:100%;" type="text" class="button-blue" content="确定"></vxe-button></div>
              <div class="margin-bottom-xs"><vxe-button style="width:100%;" type="text" class="button-blue" content="取消"></vxe-button></div> -->
              <div class="margin-bottom-xs"><vxe-button style="width:100%;" type="text" class="button-blue" content="新增" @click="addNew"></vxe-button></div>
              <div class="margin-bottom-xs"><vxe-button style="width:100%;" type="text" class="button-blue" content="删除" @click="deleteOption"></vxe-button></div>
            </div>
          </Pane>
        </Splitpanes>
      </template>
    </vxe-modal>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, getCurrentInstance, onMounted, computed, toRefs, watch } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue'; //面包屑
import { Splitpanes, Pane } from 'splitpanes';
import VxePulldownMultiSelection from '@/components/VxePulldownMultiSelection.vue';
import VxeDictSelection from '@/components/VxeDictSelection.vue';
import SelectWorkGroupAllDefaultAll from '@/views/lab_sys/lab_bus/components/SelectWorkGroupAllDefaultAll.vue'; //报告单元默认全部引入下拉组件
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { IsEmpty, formatDateTime, newGuid } from '@/utils/common';
import VxePulldownSelection from '@/components/VxePulldownSelection.vue';

let { proxy }: any = getCurrentInstance();

let loading = ref(false);
let baseItem = reactive({
  rptGroup: '',
  leVal: null,
  gtVal: null,
  txtValEq: '',
  isActive: false,
  itemNo: '',
  itemNa: ''
}) as any;
let forms = reactive([
  {
    rptGroup: '',
    leVal: null,
    gtVal: null,
    txtValEq: '',
    isActive: true,
    itemNo: '',
    itemNa: ''
  }
]);
let wLTable = ref(null);/**表格都西昂 */
let Resultloading = ref(false);
let wT = reactive({ id: null, name: '' }) as any;
let wL = reactive([]);
let tableList = reactive([]) as any[];
let form = reactive({
  rptGroup: null,
  txtValLikeFilter: 0,
  filterNullName: 1,
  orderDescByScheduleDate: 1,
  multiConditions: 0,
  enableAllConds: 0,
  insId: null,
  insName: '',
  status: '',
  sampledaS: formatDateTime(new Date().valueOf() - 7 * 24 * 60 * 60 * 1000, 'yyyy-MM-dd 00:00:00'),
  sampledaE: formatDateTime(new Date().valueOf(), 'yyyy-MM-dd 23:59:59'),
  sampleNo: null,
  reqNo: null,
  sex: '',
  patNo: '', //病历号
  bedCode: '', // 床号
  organizationUnitCode: '', //医院条码
  name: '',
  fullName: '',
  IDNo: '', //身份证号
  reqDept: null, //科室//this.userInfo.employee.defaultAuthorizeDepId
  reqdeprna: '', //IsEmpty(this.userInfo.employee.defaultAuthorizeDep) ? '' : this.userInfo.employee.defaultAuthorizeDep.name
  patType: null, //就诊类型
  patTypeNa: '',
  status: '1',
  sampleType: null,
  sampleTypeNa: '',
  applicationItemId: null,
  applicationItem: {} as any,
  barcode: null,
  diagnose: null,
  reqPurpose: null,
  telNo: null,
  itemNos: [],
  itemNa: '',
  leVal: null,
  gtVal: null,
  txtValEq: null,
  txtValNotEq: null,
  isFilterNoSpecCode: 1,
  simulateAllConds: 0,
  condOptions: [],
}) as any;
let currentStartIndex = ref(0);
let currentEndIndex = ref(20);
let currentWork = reactive({}) as any;

// 查询
function handleSearch(e) {
  if (e && e.$event && e.$event.keyCode && e.$event.keyCode === 13) {
    findRptYangXList();
  }
}

function mounted() {
  this.getSearchTemplat();
}

//获取工作列表
function searchWklt(v1, v2) {
  form.rptGroup = v1.value ? v1.value : '';
}

//获取工作列表
function searchWklt1(v1, v2, i) {
  let a = !IsEmpty(v1.value) ? v1.value : '';
  forms[i].rptGroup = a;
}
//rowClick
function handleRowClick({ row }) {
  //todo
}
//打印
let isPrinting = ref(false);
async function printTable() {
  isPrinting.value = true;
  await wLTable.value?.print();
  isPrinting.value = false;
}
//导出
function exportCVS() {
  wLTable.value?.openExport();
}
//预览报告
let fullLoading = ref(false);

function resetForm() {
  Object.assign(form, {
    rptGroup: null,
    txtValLikeFilter: 0,
    filterNullName: 1,
    orderDescByScheduleDate: 1,
    multiConditions: 0,
    enableAllConds: 0,
    insId: null,
    insName: '',
    status: '',
    sampledaS: formatDateTime(new Date().valueOf() - 7 * 24 * 60 * 60 * 1000, 'yyyy-MM-dd 00:00:00'),
    sampledaE: formatDateTime(new Date().valueOf(), 'yyyy-MM-dd 23:59:59'),
    sampleNo: null,
    reqNo: null,
    sex: '',
    patNo: '', //病历号
    bedCode: '', // 床号
    organizationUnitCode: '', //医院条码
    name: '',
    fullName: '',
    IDNo: '', //身份证号
    reqDept: null, //科室//this.userInfo.employee.defaultAuthorizeDepId
    reqdeprna: '', //IsEmpty(this.userInfo.employee.defaultAuthorizeDep) ? '' : this.userInfo.employee.defaultAuthorizeDep.name
    patType: null, //就诊类型
    patTypeNa: '',
    status: '1',
    sampleType: '',
    sampleTypeNa: '',
    applicationItemId: null,
    applicationItem: {} as any,
    barcode: null,
    diagnose: null,
    reqPurpose: null,
    telNo: null,
    itemNos: [],
    itemNa: '',
    leVal: null,
    gtVal: null,
    txtValEq: null,
    txtValNotEq: null,
    isFilterNoSpecCode: 1,
    simulateAllConds: 0,
    condOptions: [],
  })
  form.sampleTypeNa = '';
  forms.length = 0;
  forms.push({
    rptGroup: '',
    leVal: null,
    gtVal: null,
    txtValEq: '',
    isActive: true,
    itemNo: '',
    itemNa: ''
  });
}

//Pulldown下拉选中事件【科室】
function pulldownSelectConfirm(e) {
  e.aimKeys.forEach(item => {
    form[item.aimKey] = e.row[item.rowKey];
  });
}
/**标本类型，科室 */
function dropPullDownConfirm(e) {
  e.aimKeys.forEach(item => {
    form[item.aimKey] = e.row[item.rowKey];
  });
}
function pulldownSelectConfirmAnsWtId(e) {
  e.aimKeys.forEach(item => {
    this.form[item.targetField] = e.row[item.sourceField];
  });
  this.form.ans = e.row.ans;
}
function pulldownSelectConfirmAns(e) {
  e.aimKeys.forEach(item => {
    this.form[item.targetField] = e.row[item.sourceField];
  });
}
function pulldownSelectConfirm1Wtid(m, i, e) {
  e.aimKeys.forEach(item => {
    m[item.targetField] = e.row[item.sourceField];
  });
  m.ans = e.row.ans;
}
function pulldownSelectConfirm1(m, i, e) {
  e.aimKeys.forEach(item => {
    m[item.targetField] = e.row[item.sourceField];
  });
}
// 行点击事件s
function printBarcodeRowClick({ row, rowIndex }) {
  //todo
}
//获取列表
function findRptYangXList() {
  tableList.length = 0;
  loading.value = true;
  let url = '/lab/maininfo/getPositiveReports';
  form['condOptions'].length = 0;
  if (form.multiConditions) {
    Object.assign(form.condOptions, forms);
  }
  if (IsEmpty(form.leVal)) {
    form.leVal = null;
  }
  if (IsEmpty(form.gtVal)) {
    form.gtVal = null;
  }
  proxy.$http
    .post(url, form)
    .then((res: any) => {
      res.data.forEach(e => {
        e.scheduleDate = formatDateTime(e.scheduleDate, 'yyyy-MM-dd');
      });
      Object.assign(tableList, res.data);
      loading.value = false;
    })
    .catch(err => {
      loading.value = false;
    });
}
/**新增多条件 */
function addNew() {
  let a = {} as any;
  Object.assign(a, baseItem);
  forms.push(a);
}
/**条件项点击 */
let curOptionIndex = ref(-1);
function optionClick(m, i) {
  curOptionIndex.value = i;
  forms.forEach(e => {
    if (e === m) {
      e.isActive = true;
    } else {
      e.isActive = false;
    }
  });
}
/**删除项 */
function deleteOption() {
  forms.splice(curOptionIndex.value, 1);
  if (curOptionIndex.value <= forms.length - 1) {
    forms[curOptionIndex.value].isActive = true;
  } else {
    forms[forms.length - 1].isActive = true;
    curOptionIndex.value = curOptionIndex.value - 1;
  }
  proxy.$forceUpdate();
}
/**工作组选择改变 */
function wTChange(e, m) {
  m[`rptGroup`] = e.id;
  m[`wtName`] = e.name;
}
/**工作组加载完成 */
function selectWtLoaded(m, i, e) {
  //工作组加载完成
  m.rptGroup = e.id;
  m.wtName = e.name;
}
/** */
let multiCondModal = ref(false);

/**报告项目下拉选中 */
function confirmListItem(data, keyName) {
  if (keyName) {
    form[keyName + 'Nos'].length = 0;
    form[keyName + 'Ids'] = [];
    form[keyName + 'Na'] = '';
  }
  if (data.aimKeys) {
    data.aimKeys.forEach((val) => {
      form[val.targetField + 'Nos'].length = 0;
      form[val.targetField + 'Ids'] = [];
      form[val.targetField + 'Na'] = '';
    });
  }
  if (IsEmpty(data.aimKeys) || data.aimKeys.length === 0) {
    const arr = data.arr;
    form[keyName + 'Nos'] = arr;
    if (arr.length !== 0) {
      arr.forEach((item) => {
        if (item.id) {
          form[keyName + 'Ids'].push(item.id);
        } else {
          form[keyName + 'Ids'].push(item.code);
        }
        if (item.name) {
          form[keyName + 'Name'] += item.name + ',';
        } else if (item[keyName + 'Name']) {
          form[keyName + 'Name'] += item[keyName + 'Name'] + ',';
        } else {
          form[keyName + 'Name'] += item.realname + ',';
        }
      });

      if (form[keyName + 'Name'] && form[keyName + 'Name'].trim()) {
        form[keyName + 'Name'] = form[keyName + 'Name'].slice(0, -1);
      }
    }
  } else {
    data.arr.forEach((item) => {
      data.aimKeys.forEach((val) => {
        form[val.targetField + 'Nos'].push(item.itemNo);
        form[val.targetField + 'Ids'].push(item.id);
        form[val.targetField + 'Na'] += item.itemNa + ' ';
      });
    });
  }
}

/**报告项目下拉选中弹窗 */
function confirmListItem1(data) {
  forms[data.childIndex].itemNo = data.row.itemNo;
  forms[data.childIndex].itemNa = data.row.itemNa;
  proxy.$forceUpdate();
}

function confirmList(data, keyName) {
  form[keyName + 'Nos'].length = 0;
  form.itemNos.length = 0;
  form[keyName + 'Na'] = '';
  if (data.aimKeys) {
    data.aimKeys.forEach(item => {
      form[item.targetField + 's'] = [];
      form.itemNos.length = 0;
    });
  }
  if (IsEmpty(data.aimKeys) || data.aimKeys.length === 0) {
    const arr = data.arr;
    form[keyName + 's'] = arr;
    if (arr.length !== 0) {
      arr.forEach(item => {
        form[keyName + 's'].push(item.id);
        form[keyName + 'Na'] += item.name + ',';
      });

      if (form[keyName + 'Na'] && form[keyName + 'Na'].trim()) {
        form[keyName + 'Na'] = form[keyName + 'Na'].slice(0, -1);
      }
    }
  } else {
    data.arr.forEach(item => {
      data.aimKeys.forEach(val => {
        form[val.targetField + 's'].push(item);
        form.itemNos.push(item[val.targetField + 'Id']);
      });
    });
  }
}

let SearchTemplateModal = ref(false); //模板名称弹窗
let SearchTemplateName = ref(''); //弹窗输入的模板名称
let SearchTemplateList = reactive([]); //模版列表
let searchName = ref('');
// 获取查询模板
function getSearchTemplat() {
  const url = '/api/lims/work-list-statistic/template-list/' + 'rptyangxTemplate';
  proxy.$http.get(url).then(res => {
    SearchTemplateList = res.data;
  });
}

// 保存弹窗
function saveTemplate() {
  SearchTemplateModal.value = true;
}
// 保存查询模板
function saveSearchTemplate() {
  const compId = newGuid();
  // const obj = JSON.stringify(this.form);
  const obj = JSON.stringify({ form: this.form, forms: this.forms });

  const url = '/api/lims/work-list-statistic/template/' + 'rptyangxTemplate';
  const data = {
    id: compId,
    name: this.SearchTemplateName,
    template: obj
  };
  proxy.$http
    .post(url, data)
    .then(res => {
      VxeMessage('保存成功', VxeNotifyType.error);
      SearchTemplateModal.value = false; //关闭弹窗
      SearchTemplateName.value = '';
      getSearchTemplat(); //获取模板
    })
    .catch(err => {
      VxeMessage('保存失败', VxeNotifyType.error);
      SearchTemplateName.value = '';
      SearchTemplateModal.value = false;
      getSearchTemplat(); //获取模板
    });
}
let selectId = ref(''); //选中的id
// 下拉框选中发生变化
function selectChange({ value }) {
  this.selectId = value.id;
  this.searchName = value.name;
  const newObj = JSON.parse(value.template);
  newObj.form.sampledaS = this.form.sampledaS;
  newObj.form.sampledaE = this.form.sampledaE;
  this.form = newObj.form;
  this.forms = newObj.forms;
}
// 删除模板
function deleteTemplate() {
  const url = '/api/lims/work-list-statistic/template/' + 'rptyangxTemplate/' + this.selectId;
  this.$confirm('确定删除此记录？', '提示', {
    cancelButtonClass: 'cancvxe-button',
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
    closeOnClickModal: true
  })
    .then(() => {
      this.axios
        .delete(url)
        .then(res => {
          NotifyMessage('删除成功', NotifyType.success, this);
          this.searchName = '';
          this.getSearchTemplat(); //获取模板
        })
        .catch(err => {
          NotifyMessage('删除失败', NotifyType.error, this);
          this.searchName = '';
          this.getSearchTemplat(); //获取模板
        });
    })
    .catch(() => { });
}

//Pulldown下拉选中事件
function pulldownSelectConfirmTree(e, data) {
  e.aimKeys.forEach(item => {
    data.wtName = e.row.name;
    data.rptGroup = e.row.id;
  });
}

function selectClearHandler() {
  this.form.status = '';
}
/**性别选中 */
function dropSelectConfirm(e) {
  console.log('性别选中', e);
}
</script>
<style lang="scss" scoped>
#reportSearchList {
  height: 100%;

  .bodyContent {
    height: calc(100% - 60px);

    :deep(.el-tabs__header) {
      margin: 0 !important;
    }

    :deep(.el-tabs) {
      height: 100%;

      .el-tabs__content {
        height: calc(100% - 41px);
      }
    }
  }

  .splitpanes {
    background-color: $base-white;
    height: 100%;
  }

  :deep(.splitpanes__pane) {
    overflow: visible;
  }
}
.width-100-percentage {
  width: 100%;
}
:deep(.vxe-input--inner) {
  border-radius: 4px !important;
}
</style>
